package br.com.duosoftware.orcamento.entidades;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

/**
 *
 * @author Daniel
 * 
 */

@Entity
@Table(name="periodos_de_programa")
public class PeriodoDePrograma implements Serializable{
    
    @Id
    @GeneratedValue(strategy= GenerationType.IDENTITY)
    private Integer id;
    //
    private int anoInicial;
    //
    private int anoFinal;
    //
    private String tipoDePeriodo;
    
    @ManyToMany
    @JoinTable(name="programas_periodos", 
            joinColumns={@JoinColumn(name="periodo_de_programa_id")},
            inverseJoinColumns={@JoinColumn(name="programa_id")})
    private List<Programa> programa;
    
    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int getAnoInicial() {
        return anoInicial;
    }

    public void setAnoInicial(int anoInicial) {
        this.anoInicial = anoInicial;
    }

    public int getAnoFinal() {
        return anoFinal;
    }

    public void setAnoFinal(int anoFinal) {
        this.anoFinal = anoFinal;
    }

    public List<Programa> getPrograma() {
        return programa;
    }

    public void setPrograma(List<Programa> programa) {
        this.programa = programa;
    }

    public String getTipoDePeriodo() {
        return tipoDePeriodo;
    }

    public void setTipoDePeriodo(String tipoDePeriodo) {
        this.tipoDePeriodo = tipoDePeriodo;
    }
    
    @Override
    public int hashCode() {
        int hash = 3;
        hash = 11 * hash + (this.id != null ? this.id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final PeriodoDePrograma other = (PeriodoDePrograma) obj;
        if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return anoInicial + " à " + anoFinal;
    }
    
}
